package com.eastedu.repository.basic.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.eastedu.repository.basic.po.ResourceSourcePO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * The interface Basic resource file mapper.
 *
 * @author ZHISHUAI.ZHANG
 * @since 2019 /2/22
 */
@Mapper
public interface ResourceSourceMapper extends BaseMapper<ResourceSourcePO> {

    /**
     * Update provider.
     *
     * @param oldProvider     the old provider
     * @param newProvider     the new provider
     * @param basicResourceId the basic resource id
     */
    @Update("UPDATE t_resource_source SET provider = #{newProvider}, update_time = update_time + 1 WHERE resource_id = #{basicResourceId} AND provider = #{oldProvider}")
    void updateProvider(@Param("oldProvider") int oldProvider, @Param("newProvider") int newProvider, @Param("basicResourceId") Long basicResourceId);

    /**
     * Update apply time.
     *
     * @param applyTimeStart  the apply time start
     * @param applyTimeEnd    the apply time end
     * @param basicResourceId the basic resource id
     */
    @Update("UPDATE t_resource_source SET apply_time_start = #{applyTimeStart}, apply_time_end = #{applyTimeEnd}, update_time = update_time + 1 WHERE resource_id = #{basicResourceId} AND apply_time_start IS NULL")
    void updateApplyTime(@Param("applyTimeStart") Long applyTimeStart, @Param("applyTimeEnd") Long applyTimeEnd, @Param("basicResourceId") Long basicResourceId);
}
